var pGrid,machsn, partner_id, mach_data;
$(function() {
    $("#form_core").height($(".form_tab").height()-$("#form_option").outerHeight());
    $('#myTabs a').click(function (e) {
        e.preventDefault()
        $(this).tab('show')
    });
    // 明细列表设置
    pGrid = $("#p-div").ligerGrid({
        columns:[
            {display:'用户编号',name:'userid',width:'100'},
            {display:'用户名称',name:'username',width:'100'},
            {display:'用户密码',name:'password',width:'100'},
            {display:'用户权限',name:'privilege',width:'100'},
            {display:'启用标志',name:'enabled',width:'100'},
        ],
        pageSize:20,
        height:'99%',
        width:'96%',
        rownumbers:true,
        frozen:false,
        fixedCellHeight:false,
        enabledEdit:true,
        onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
        param_partner:'partner_list',
        alternatingRow: true,
        clickToEdit: true,
        isScroll: false,
        usePager:true,
        editorTopDiff:4,
        editorLeftDiff:2
    });
    var query = getQueryString(window.location.toString());
    machsn = query.machsn;
    ajaxSubmitGet("/attendance/searchMach/" + machsn, function(data) {
        //绑定数据
        bindVal(data);
        getMachInfo();
    });
    $("#pageloading").hide();
});

function bindVal(data) {
    mach_data = data['data'];
    var isused = "";
    //绑定主表数据
    $("#machip").html(mach_data.machip);
    $("#machcode").html(mach_data.machcode);
    $("#machmac").html(mach_data.machmac);
    $("#machsn").html(mach_data.machsn);
    $("#machname").html(mach_data.machname);
    $("#machable").html(mach_data.machable);
    $("#dept_id").html(paramRender(null, 'org_list', mach_data.dept_id));
    $("#machaddress").html(mach_data.machaddress);
    if(mach_data.machuse=="1"){
    	isused = "考勤设备";
    }else{
    	isused = "采集设备";
    }
    $("#IsmachUsed").html(isused);
}

function getMachInfo(){
	var machip = mach_data.machip;
	var machcode = parseInt(mach_data.machcode);
	var machStatusStr = faceApplet.getDeviceStatus(machip,machcode);
	var machstatus = JSON.parse(machStatusStr);
	 $("#userNum").html(machstatus.userNum);
	 $("#faceNum").html(machstatus.faceNum);
	 $("#attendNum").html(machstatus.attendNum);
	 $("#userCap").html(machstatus.userCap);
	 $("#faceCap").html(machstatus.faceCap);
	 $("#attendCap").html(machstatus.attendCap);
	var machuserInfostr = faceApplet.GetAllUserInfo(machip,machcode);
	var machuserInfo = JSON.parse(machuserInfostr);
    //明细列表数据加载
    pGrid.setOptions({
        data : {
            Rows : machuserInfo
        }
    }); //设置数据参数
    pGrid.loadData();//加载数据
}


//界面的返回处理，实际是关闭标签处理。
function toBack() {
    parent.tabManager.removeTabItem("search_mach"+machsn);
}